%% This function creates those nice MatFiles which visualize the quadcopters...
%  The output is a structure called "a" !!
%  (and yes, this is how even MatLab example scripts call their
%  structures...)

%% closing stuff at the beginning
close all;                  % close all figures
clear all;                  % clear all workspace variables
clc;                        % clear the command line
fclose('all');              % close all open files


%% create copter
a.name = 'copter';
D = 100;                % Diameter of the copter
B = 5;                  % Relation Height / Thickness
F = 25;                 % Length of different color patch to determine which direction the copter is pointing

D = D/100;
B = B/100;
F = F/100;

R = (D/2);
H = (B/2);

a.faces = [ 1  2  3  4  5  6  7  8  9 10 11 12;             % down
           14 15 16 17 18 19 20 21 22 23 24 25;             % up
           13 14 25 26 26 26 26 26 26 26 26 26;             % little patch which shows the copter nose
           13  1 12 26 26 26 26 26 26 26 26 26;  
            1  2 15 13 13 13 13 13 13 13 13 13;
            2  3 16 15 15 15 15 15 15 15 15 15;
            3  4 17 16 16 16 16 16 16 16 16 16;
            4  5 18 17 17 17 17 17 17 17 17 17;
            5  6 19 18 18 18 18 18 18 18 18 18;
            6  7 20 19 19 19 19 19 19 19 19 19;
            7  8 21 20 20 20 20 20 20 20 20 20;
            8  9 22 21 21 21 21 21 21 21 21 21;
            9 10 23 22 22 22 22 22 22 22 22 22;
           10 11 24 23 23 23 23 23 23 23 23 23;
           11 12 26 24 24 24 24 24 24 24 24 24];
        

a.vertices = [-R      -H        H;
              -H      -H        H;
              -H      -H        R;
               H      -H        R;
               H      -H        H;
               R      -H        H;
               R      -H       -H;
               H      -H       -H;
               H      -H       -R;
              -H      -H       -R;
              -H      -H       -H;
              -R      -H       -H;
              
              -R       H        H;
              (-R) + F H        H;
              -H       H        H;
              -H       H        R;
               H       H        R;
               H       H        H;
               R       H        H;
               R       H       -H;
               H       H       -H;
               H       H       -R;
              -H       H       -R;
              -H       H       -H;
              (-R) + F H       -H;
              -R       H       -H];
    
          
          
a.cdata = [ 1       0     1;                              
            1       0     1;                              
            1       1     0;                        
            1       1     1;
            1       0     1;
            1       0     1;
            1       0     1;
            1       0     1;
            1       0     1;
            1       0     0;
            1       0     1;
            1       0     1;
            1       0     1;
            1       0     1;
            1       0     1];
            
       
c(1,1,1:3)=     [ 1      0    1];          
c(1,2,1:3)=     [ 1      0    1];
c(1,3,1:3)=     [ 1      1    0];
c(1,4,1:3)=     [ 1      1    1];
c(1,5,1:3)=     [ 1      0    1];
c(1,6,1:3)=     [ 1      0    1];
c(1,7,1:3)=     [ 1      0    1];
c(1,8,1:3)=     [ 1      0    1];
c(1,9,1:3)=     [ 1      0    1];
c(1,10,1:3)=    [ 1      0    0];
c(1,11,1:3)=    [ 1      0    1];
c(1,12,1:3)=    [ 1      0    1];
c(1,13,1:3)=    [ 1      0    1];
c(1,14,1:3)=    [ 1      0    1];
c(1,15,1:3)=    [ 1      0    1];

h_patch   = patch('Vertices',a.vertices,'Faces',a.faces, 'CData', c, 'FaceColor', 'flat');
view(3);
set(gca, 'XLim', [-0.5 0.5], 'YLim', [-0.5 0.5], 'ZLim', [-0.5 0.5]);
% set(gca, 'YDir', 'reverse')                 % reverse Y and Z direction
% set(gca, 'ZDir', 'reverse')
grid on;
axis vis3d